﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using blackhouse.BlackApart.Business.ApartmentServices;
using blackhouse.BlackApart.Business.Reservations;

namespace blackhouse.BlackApart.Business {
    public class ReservationPrice {

        #region Fields

        private IWebReservation reservation;
        private bool includeRabat = true;
        private double reservationPrice;
        private double totalPrice;
        private bool calculated;

        #endregion

        #region Properties

        public bool IncludeRabat {
            get {
                return this.includeRabat;
            }
            set {
                if (this.includeRabat != value) {
                    this.calculated = false;
                    this.includeRabat = value;
                }
            }
        }

        public double ReservationCost {
            get {
                this.Calculate();
                return this.reservationPrice;
            }
            private set { this.reservationPrice = value; }
        }

        public double TotalCost {
            get {
                this.Calculate();
                return this.totalPrice;
            }
            private set { this.totalPrice = value; }
        }

        public bool SupportAdditionalServices {
            get;
            set;
        }
        #endregion

        #region Constructors

        public ReservationPrice(IWebReservation reservation) {
            this.reservation = reservation;
            this.SupportAdditionalServices = true;
        }

        public ReservationPrice(IWebReservation reservation, bool includeRabat) {
            this.reservation = reservation;
            this.IncludeRabat = includeRabat;
            this.SupportAdditionalServices = true;
        }

        #endregion

        #region Methods

        private void Calculate() {
            if (this.calculated) return;

            double price = this.reservation.FinalPrice; // to jest cena z rabatem
            if (!this.IncludeRabat && this.reservation.Rabat != 0)
                price = price - price * this.reservation.Rabat / 100; // Jest - ponieważ wartość rabatu też jest -, czyli -- daje +.
            this.ReservationCost = price;

            if (this.SupportAdditionalServices) {
                ReservationServices rServices = new ReservationServices(this.reservation);
                this.TotalCost = price + rServices.TotalCost;
            }
            else
                this.TotalCost = price;
            this.calculated = true;
        }

        #endregion

    }
}
